package com.health.utils;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class ConnectionUtil {
    private static Connection conn = null;

    public static Connection getConnection() {
        try {
            Properties properties = new Properties();
            InputStream resourceAsStream = ConnectionUtil.class.getClassLoader().getResourceAsStream("jdbc.properties");
            properties.load(resourceAsStream);
            Class.forName(properties.getProperty("jdbc.driver"));
            conn = DriverManager.getConnection(properties.getProperty("jdbc.url"), properties.getProperty("jdbc.username"), properties.getProperty("jdbc.password"));
            System.out.println("数据库连接成功");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("数据库连接失败");
        }
        return conn;
    }
}


